<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="/Public/Admin/extend/lib/html5shiv.js"></script>
    <script type="text/javascript" src="/Public/Admin/extend/lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="/Public/Admin/extend/static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="/Public/Admin/extend/static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="/Public/Admin/extend/lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="/Public/Admin/extend/static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="/Public/Admin/extend/static/h-ui.admin/css/style.css" />
    <!--[if IE 6]>
    <script type="text/javascript" src="/Public/Admin/extend/lib/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>

    <![endif]-->
    <title>添加救护类型 - 救护管理</title>
    <style>
        .filea {
            position: relative;
            display: inline-block;
            background: #D0EEFF;
            border: 1px solid #99D3F5;
            border-radius: 4px;
            padding: 4px 12px;
            overflow: hidden;
            color: #1E88C7;
            text-decoration: none;
            text-indent: 0;
            line-height: 20px;
        }
        .filea input {
            position: absolute;
            font-size: 100px;
            right: 0;
            top: 0;
            opacity: 0;
        }
        .filea:hover {
            background: #AADFFD;
            border-color: #78C3F3;
            color: #004974;
            text-decoration: none;
        }

        .upimg_block .showimg{height: auto; width: auto\9; }
        .upimg_block .imglist_box{}
        .upimg_block .imglist_box{ width:100%; margin:auto; }
        .upimg_block .imglist_box ul{float:left; width:50%; margin-bottom:20px;}
        .upimg_block .imglist_box li{margin:auto; float:left; width:33%; text-align:center; }
        .upimg_block .imglist_box li img{ width:100%; height:80px;}
        .upimg_block .imglist_box li a{ margin:5px; display:block;}
        .typea{background: #AADFFD;}
    </style>
</head>
<body>
<article class="page-container">
    <span style="color:gray;fone-size:1.2em">救护类型添加</span>
    <form class="form form-horizontal" id="form-admin-add">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>名称：</label>
            <div class="formControls col-xs-8 col-sm-10">
                <input type="text" class="input-text" value="" placeholder="" id="name" name="name">
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>状态：</label>
            <div class="formControls col-xs-8 col-sm-10 skin-minimal">
                <div class="radio-box">
                    <input name="status" type="radio" id="status-0"  value="0">
                    <label for="status-0">关闭</label>
                </div>
                <div class="radio-box">
                    <input type="radio" id="status-1" name="status" checked value="1">
                    <label for="status-1">开启</label>
                </div>
            </div>
        </div>
        <div class="row cl img">
            <label class="form-label col-xs-4 col-sm-2">图标：</label>
            <div class="formControls col-xs-8 col-sm-10">
                <div class="upimg_block">
                    <div class="select_box" style="height:70px">
                        <div class="load_box" id="load_cover" ></div>
                        <div>
                            <div class="btn_box" style="float:left;margin-top:25px;" style="height:60px">
                                <a href="javascript:;" class="filea">请选择（最多上传1张图片）
                                    <input type="file"  class="file" id="cover" name="cover">
                                </a>
                            </div>
                            <div style="float:left;margin-left:10px;" id="show_cover_img">

                            </div>
                            <div style="clear:both;"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
       

        <div class="row cl">
            <div class="col-xs-8 col-sm-11 col-xs-offset-4 col-sm-offset-3">
                <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;添加&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</article>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="/Public/Admin/extend/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="/Public/Admin/extend/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="/Public/Admin/extend/static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="/Public/Admin/extend/static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="/Public/Admin/extend/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="/Public/Admin/extend/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="/Public/Admin/extend/lib/jquery.validation/1.14.0/messages_zh.js"></script>

<script src="/Public/Admin/extend/lib/exif.js?v=b26c6d5"></script>
<script src="/Public/Admin/extend/lib/lrz.js?v=c105d63"></script>
<script type="text/javascript">
    window.onload = function(){
        // //上传封面图片
        document.getElementById('cover').onchange = function(e){
            var theEvent = window.event || e;
            var img = theEvent.target.files[0];

            var img_box = $('#show_cover_img img').length;
            if(img_box>0){
                layer.msg("上传图片数目不可以超过1个", {icon: 2, time: 1000});
                return false;
            }

            //判断图片格式
            if(!(img.type.indexOf('image')==0 && img.type && /\.(?:gif|jpg|jpeg|png|GIF|JPG|PNG)$/.test(img.name)) ){
                layer.msg("图片只能是jpg,gif,png", {icon: 2, time: 1000});
                return ;
            }
            var reader = new FileReader();
            reader.readAsDataURL(img);

            reader.onload = function(e){ // reader onload start
                //alert("q");
                //压缩图片
                lrz(img, {
                    before: function() {
                        console.log('压缩开始');
                    },
                    fail: function(err) {
                        console.error(err);
                    },
                    always: function() {
                        console.log('压缩结束');
                    },
                    done: function (results) {

                        // 你需要的数据都在这里，可以以字符串的形式传送base64给服务端转存为图片。
                        //demo_report('客户端预压的图片', results.base64, results.base64.length * 0.8);
                        // ajax 上传图片
                        $('#load_cover').html('正在上传照片...');

                        $.post("<?php echo U('Admin/Admin/uploadTempPic');?>", { Upload_img: results.base64},function(ret){
                            $('#load_cover').hide();
                            if(ret.status != undefined) {
                                if (!ret.status) {
                                    layer.msg(ret.info, {icon: 2, time: 1000});
                                    return;
                                }
                            }
                            if(ret.Upload_img!=''){
                                layer.msg("上传成功", {icon: 6, time: 1000});
                                img_html='<img style="height:70px" src="' + ret.Upload_img + '">';
                                img_html+='<input type="hidden" name="cover_pic" value="'+ret.Upload_img+'">';
                                $('#show_cover_img').append(img_html);
                                $("#show_cover_img").reset();
                            }else{
                                layer.msg("上传失败", {icon: 2, time: 1000});
                            }
                        },'json');
                    } //done end
                });
            } // reader onload end
        }
    };


    $(function(){
        $('.skin-minimal input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        });

        $("#form-admin-add").validate({
            rules:{
                name:{
                    required:true,
                },
                status:{
                    required:true,
                },
            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                $(form).ajaxSubmit({
                    type: 'post',
                    url: "<?php echo U('Admin/Rescue/categoryAdd');?>" ,
                    success: function(data){
                        //alert(data);
                        if(data.status){
                            layer.msg(data.info,{icon:6,time:1000});
                            setTimeout((function() {
                                parent.window.location.href="<?php echo U('Admin/Rescue/categoryList',array('id'=>$data['id']));?>";
                            }), 1500);
                        }else{
                            layer.msg(data.info,{icon:6,time:1000});
                        }
                    },
                    error: function(XmlHttpRequest, textStatus, errorThrown){
                        layer.msg('error!',{icon:5,time:1000});
                    }
                });
            }
        });
    });
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>